
import java.util.EmptyStackException; //异常类型
import java.util.Stack;	//栈类的引用

public class Stackdemo
{
	static void showpush(Stack<Integer> st, int a) {
		st.push(new Integer(a));
		System.out.println("push("+ a +")");
		System.out.println("statck: "+ st);
	}
	static void showpop(Stack <Integer> st) {
		System.out.print("pop -> ");
		Integer a = (Integer) st.pop();
		System.out.println(a);
		System.out.println("stack: "+ st);
	}

	public static void main(String[] args)
	{
		Stack <Integer> st = new Stack<Integer>(); //Integer 类型的栈
		System.out.println("stack:" + st);

		showpush(st,1);
		showpush(st,2);
		showpush(st,3);
		showpop(st);
		showpop(st);
		showpop(st);

		try {				//捕获异常
			showpop(st);
		}catch(EmptyStackException e) {
			System.out.println("empty stack");
		}
	}

}
